const UserDao = require('../dao/user');
const ValidatorUser = require('../validators/user');
const ok = require('../core/response-shortcut');


class userController {

    static async rdUser(ctx) {
        // 接收客户端参数
   
        let req = ctx.request.query;
        ctx.response.status = 200;
        // ctx.append('Access-Control-Max-Age', '1800');
        //验证器,如果验证不通过,直接在验证器里报错
        if (req.id) {
            await ValidatorUser.rdUser(req.id)
            let res 
            if (req.api === 'forbidden') {
                //这里不是删除,而是封禁账号
                res = await UserDao.dUser(ctx);
            } else { 
                res = await UserDao.rUser(req.id);
            }
            ctx.body = ok.json(res)
        } else {
             let res = await UserDao.getAllUser(req);
             ctx.body = ok.json(res)
        }
    }

    static async cuUser(ctx) { 
        let res = await UserDao.uUser(ctx);
        ctx.response.status = 200;
        ctx.body = ok.update(res)
    }
}
module.exports = userController